package com.polonium.eclipserunner.webdriver;

import com.polonium.eclipserunner.core.PoloniumTest;
import com.polonium.eclipserunner.core.annotations.MarkedGivenFail;
import com.polonium.eclipserunner.core.annotations.MarkedWhenFail;
import com.polonium.eclipserunner.core.exceptions.ThenException;
import org.junit.After;
import org.junit.runner.RunWith;
import org.openqa.selenium.ElementNotVisibleException;
import org.openqa.selenium.IllegalLocatorException;
import org.openqa.selenium.ImeActivationFailedException;
import org.openqa.selenium.ImeNotAvailableException;
import org.openqa.selenium.InvalidCookieDomainException;
import org.openqa.selenium.InvalidElementStateException;
import org.openqa.selenium.InvalidSelectorException;
import org.openqa.selenium.NoAlertPresentException;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.NoSuchFrameException;
import org.openqa.selenium.NoSuchWindowException;
import org.openqa.selenium.NotFoundException;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.UnableToSetCookieException;
import org.openqa.selenium.UnhandledAlertException;
import org.openqa.selenium.UnsupportedCommandException;
import org.openqa.selenium.WebDriverException;

/** Specify test runner and define JUnit after method which quits driver. Contains list of exception that are marked as polonium exceptions
 * 
 * @author Marek Serwanski
 */

@RunWith(PoloniumWebdriverTestRunner.class)
@MarkedGivenFail({UnsupportedCommandException.class})
@MarkedWhenFail({
	NoSuchElementException.class,
	ElementNotVisibleException.class,
	IllegalLocatorException.class,
	ImeActivationFailedException.class,
	ImeNotAvailableException.class,
	InvalidCookieDomainException.class,
	InvalidElementStateException.class,
	InvalidSelectorException.class,
	NoAlertPresentException.class,
	NoAlertPresentException.class,
	NoSuchFrameException.class,
	NoSuchWindowException.class,
	NotFoundException.class,
	StaleElementReferenceException.class,
	TimeoutException.class,
	UnableToSetCookieException.class,
	UnhandledAlertException.class,
	WebDriverException.class
})
public class PoloniumWebdriver extends PoloniumTest{

	@After
	public void closeTestWindow(){
		try{
			DriverFactory.getDriver().quit();
			DriverFactory.clearDriver();
		} catch(Exception e){
			throw new ThenException("Unnable to quit test\n" + e.getMessage());
		}
	}
}
